<template>
	<view class="memberLevelSettingContainer">
		<view class="carder">
			<view class="title font-weight_bold">
				等级一
			</view>
			<view class=" margin-top_20rpx">
				<view class="flex-start-center">
					<view class="line">
					
					</view>
					<view class="margin-left_20rpx">
						会员名字
					</view>
				</view>
				<view class="edit flex-start-center padding-left_30rpx margin-top_20rpx">
					<input class="uni-input" v-model="form.name" placeholder="请输入会员等级" />
				    
				
				</view>
			</view>
			<view class=" margin-top_20rpx">
				<view class="flex-start-center">
					<view class="line">
					
					</view>
					<view class="margin-left_20rpx">
						消费金额
					</view>
				</view>
				<view class="edit flex-start-center padding-left_30rpx margin-top_20rpx">
					<input class="uni-input" :disabled="id==1?true:false" v-model="form.consumption_amount" placeholder="请输入消费金额" />
				    
				
				</view>
				<view class="margin-top_20rpx">
					<text style="color: rgb(255, 0, 0);">备注：达到多少消费享受此折扣</text>
				</view>
			</view>
			<view class=" margin-top_20rpx">
				<view class="flex-start-center">
					<view class="line">
					
					</view>
					<view class="margin-left_20rpx">
						全局折扣设置
					</view>
				
				</view>
				<view class="edit flex-start-center padding-left_30rpx margin-top_20rpx">
					<input class="uni-input" maxlength="3" type="number" v-model="form.preferential" placeholder="请输入全局折扣设置" />
				    
				
				</view>
				<view class="margin-top_20rpx">
					<text style="color: rgb(255, 0, 0);">备注：以百分比形式(如95%等于全局购买商品享受9.5折优惠)</text>
				</view>
			</view>
			<view class=" margin-top_20rpx">
				<view class="flex-start-center">
					<view class="line">
					
					</view>
					<view class="margin-left_20rpx">
						商城折扣设置
					</view>
				</view>
				<view class="edit flex-start-center padding-left_30rpx margin-top_20rpx">
					<input class="uni-input" maxlength="3" type="number" v-model="form.shopping_preferential" placeholder="请输入商城折扣设置" />

				</view>
				<view class="margin-top_20rpx">
					<text style="color: rgb(255, 0, 0);">备注：仅限商城商品享受 </text>
				</view>
			</view>
			<view class=" margin-top_20rpx">
				<view class="flex-start-center">
					<view class="line">
					
					</view>
					<view class="margin-left_20rpx">
						套餐卡折扣设置
					</view>
				</view>
				<view class="edit flex-start-center padding-left_30rpx margin-top_20rpx">
					<input class="uni-input" maxlength="3" type="number" v-model="form.package_preferential" placeholder="请输入套餐卡折扣设置" />
				    
				
				</view>
				<view class="margin-top_20rpx">
					<text style="color: rgb(255, 0, 0);">备注：仅限商城商品享受</text>
				</view>
			</view>
			<view class="btnSure flex" @click="newAdd()">
				{{isEdit?"编辑":'添加'}}
			</view>
		</view>
	</view>

</template>

<script>
	import {
		object2Url
	} from '@/utils/trans';
	export default {
		components: {

		},
		data() {
			return {
				tabIndex: 4,

				form: {
					// 会员名字
					name: '',
					// 消费金额
					consumption_amount: '',
					// 全局折扣
					preferential: '',
					// 商品折扣
					shopping_preferential: "",
					// 套餐折扣
					package_preferential: '',
					
				},
				imgFormData: null,
				ossInfo: null,
				upPicUrl: null,
				upPicUrl2: null,
				imgStr: [],
				img: [],
				imgStr2: [],
				img2: [],
				isEdit: false,
				storageMode: "2",
				isEdit: false,
				header: null,
				isLogo: false,
                id:'',
				items: [{
						value: '1',
						name: '样式一',
						checked: 'true'
					},
					{
						value: '2',
						name: '样式二'
					},
					{
						value: '3',
						name: '样式三'
					},
					{
						value: '4',
						name: '自定义'
					},

				],
				
				current: 0,
				// 是否为自定义
				isCustom: false,
				token: uni.getStorageSync('login').token,
				// 背景样式
				// backgroundStyle: '../../static/套餐卡背景/矩形 1590.png'
	            downOption: {
	            	auto: true
	            },
	            // 上拉配置项
	            upOption: {
	            	auto: true
	            },
	            token: uni.getStorageSync('login').token,
	            windowHeight: '',
	            list: [],
				
			}
		},
		
		onLoad(options) {
			if (options.id) {
				this.form.id = ''
               this.id = options.id
				this.$sun.assignObject(this.form, {
					...options
				})
				

				this.isEdit = true
				
				console.log(this.form)
			}
		},
		onShow() {
			this.$at.releaseKey('submit');
		},
		methods: {
			
			// 添加套餐管理
			newAdd() {
				this.$at.uniDoFunc({
					key: 'submit',
					success: async () => {
						this.$at.lockKey('submit');
						// 登录 需要进行判断当前账号密码 和账号归属店铺及角色是否又选择
						if (!this.form.name) {
							this.$sun.toast("请输入会员名称", 'none')
							this.$at.releaseKey('submit');
						} else if (!this.form.consumption_amount) {
							this.$sun.toast("请输入消费金额", 'none')
							this.$at.releaseKey('submit');
						} else if (!this.form.preferential) {
							this.$sun.toast("请选择全局折扣", 'none')
							this.$at.releaseKey('submit');
						} else if (!this.form.shopping_preferential) {
							this.$sun.toast("请填写商品折扣", 'none')
							this.$at.releaseKey('submit');

						} else if (!this.form.package_preferential) {

							this.$sun.toast("请填写套餐卡折扣", 'none')
							this.$at.releaseKey('submit');

						}else {
							this.form.preferential=Number(this.form.preferential)
							this.form.shopping_preferential=Number(this.form.shopping_preferential)
							this.form.package_preferential=Number(this.form.package_preferential)
							console.log(this.form)
							const saveOrUpdate = this.isEdit ? this.$api.editLevel : this.$api.addLevel;
							const formUpdata= this.isEdit?{'level':[{...this.form}]} :{...this.form};
							console.log(formUpdata)
							const res = await this.$http.post({
								url: saveOrUpdate,
								data: formUpdata,
								headers: {
									'Authorization': `Bearer ${this.token}`
								}

							})
							console.log(res)
							if (res.code == 0) {

								this.$sun.toast(res.msg, 'none')

								// 跳转到登录页面
								this.$at.releaseKey('submit');

								setTimeout(() => {
									this.$sun.navBack()
								}, 500)

							} else {
								this.$at.releaseKey('submit');
								this.$sun.toast(res.msg, 'none')
							}
						}
					}
				});
			},
		
			


		}
	}
</script>

<style lang="less" scoped>
	.memberLevelSettingContainer {
		margin: 14rpx;
         .btnSure {
         	width:93%;
         	height: 76rpx;
         	background: rgb(81, 142, 247);
         	color: rgb(255, 255, 255);
         	border-radius: 108rpx;
         	font-size: 32rpx;
         	font-weight: 700;
         	position: fixed;
         	bottom: 20rpx;
         }
		.carder {
			.title{
				font-size: 36rpx;
			}
			padding: 14rpx;
			background-color: #fff;

			.line {
				
				width: 4px;
				height: 14px;
				background: rgb(50, 113, 253);
			}
			.edit {
			
				height: 88rpx;
				background: rgb(246, 248, 255);
			
			
			
			}
		}
	}
</style>